<template>
  <div class="page-joinview">
    <div class="page-joinview-content">
      <div class="page-joinview-box" v-if="show">
        <div class="page-joinview-title bold mb-12">面试邀请函</div>
        <el-form label-width="auto">
          <el-form-item label="面试公司:">{{ curData.company_name }}</el-form-item>
          <el-form-item label="面试岗位:">{{ curData.job_name }}</el-form-item>
          <el-form-item label="截至日期:">{{ curData.time }}</el-form-item>
        </el-form>
        <div class="page-joinview-footer flex-row justify-center">
          <div class="mr-12" >
            <pk-button type="success" @click="handlerAccept(1)">接受</pk-button>
          </div>
          <div>
            <pk-button type="danger" @click="handlerAccept(0)">拒绝</pk-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import AES from '@/utils/AESHelper'
import { getInterviewId, getTimeYearStr } from '@/utils/utils'
import pkDialog from '@/components/pkui/pkdialog/pkdialog.vue'
import { invitationGetDetailInfo, invitationBindUser, invitationOperate } from '@/api/api'
import pkButton from '@/components/pkui/pkbutton/pkbutton.vue'
const route = useRoute()
const router = useRouter()
const InterviewId = ref('')
const curData = ref({})
const show = ref(false)
const handerInterviewId = () => {
  invitationGetDetailInfo({
    interview_id: InterviewId.value
  }).then(res => {
    if (res.data.state!=null || res.data.state!=undefined) {
      router.push({
        path: '/myinterview'
      })
      return
    }
    curData.value = {
      ...res.data,
      time: getTimeYearStr(res.data.deadline)
    }
    show.value = true
    console.log('=-------------------', res)
  }).catch(err => {
    if (err.code == 3001) {
      router.push({
        path: '/myinterview'
      })
    }
    console.log('=------err-------------', err)
  })
}


const handlerAccept = (e) => {
  invitationOperate({
    interview_id: InterviewId.value,
    is_accept: e
  }).then(res => {
    router.push({
      path: '/myinterview'
    })
  })
}

const getInit = () => {
  const { key } = route.query

  // console.log(key)
  // let ends = AES.decrypt(key)
  // console.log('=-------ends------------', ends)
  InterviewId.value = key
  handerInterviewId()
}

// 绑定邀请含
const getinvitationBindUser = () => {
  invitationBindUser({
    interview_id: InterviewId.value
  }).then((res) => {
    handerInterviewId()
    console.log('--------getinvitationBindUser-----------', res)
  })
}

onMounted(() => {
  // 先解析URL加密信息
  getInit()
  // 然后绑定邀请函信息
  getinvitationBindUser()
  // handerInterviewId()
})  
</script>

<style lang="scss" scoped>
.page-joinview{
  padding-top: 50px;
  &-content{
    width: 996px;
    margin: 0 auto;
    height: calc(100vh - 80px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  &-title{
    text-align: center;
    font-size: 16px;
  }
  &-box{
    padding: 24px;
    border: #ddd 1px solid;
    background: #fff;
    min-width: 400px;
    min-height: 200px;
    border-radius: 12px;
    font-size: 12px;
  }

  &-footer{
    
  }

}
</style>